package tings;

import java.util.ArrayList;
import java.util.HashMap;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Shape;
import LBC.CollisionListener;
import Objects.Body;
import Objects.BodyCircle;
import Objects.BodyRectangle;
import tings.Moves;

//1m=10px
//1s=60frames

public class SimpleTest extends BasicGame {

	ArrayList<Shape> shapes;
	HashMap<Shape, Body> stb;
	HashMap<Shape, BodyRectangle> str;
	HashMap<Shape, BodyCircle> stc;
	BodyRectangle r1;
	BodyRectangle r2;
	BodyCircle c1;
	BodyCircle c2;
	CollisionListener listener;
	Moves mover;
	float []points;
	Integer time;
	float VXmax;
	float VYmax;
	
	
	public SimpleTest() {
		super("SimpleTest"); } 
	
	@Override
	public void init(GameContainer container) throws SlickException {
//		container.setMinimumLogicUpdateInterval(1); //for higher works slower
//		container.setMaximumLogicUpdateInterval(30); //IMPORTANT FOR ANIMATIONS
		container.setTargetFrameRate(60);
		initialization();	
		
	}
	
	@Override
	public void update(GameContainer container, int delta) throws SlickException {

			
			Input in=container.getInput();
			if(in.isKeyDown(Input.KEY_R)){
                initialization();
			}
			mover.move();
			listener.bodyChecker2();
			time++;
			//System.out.println("simpletime="+time);
		//	System.out.println(r1.angularVelocity+" "+r2.angularVelocity);
	}
	
	@Override
	public void render(GameContainer container, Graphics g) throws SlickException {
		
		g.setColor(r1.color);
		g.fill(r1.polygon);
		g.setColor(r2.color);
		g.fill(r2.polygon);	
//		g.setColor(c1.color);
//		g.fill(c1.circle);
		
	}
	
	private void initialization(){
		time=1;
		shapes=new ArrayList<Shape>();
		stc=new HashMap<Shape, BodyCircle>();
		str=new HashMap<Shape, BodyRectangle>();
		stb=new HashMap<Shape, Body>();
		r1=new BodyRectangle(1, 700, 200, 40, 40);
		r2=new BodyRectangle(1, 200, 100, 40, 40);
		c1=new BodyCircle(1,200,100,27);
		c1.setVx(15);
		c1.setVy(-2);
		r2.setVx(15);
		r2.setVy(-2);
		r1.setVx(-7);
		r1.setVy(-5);
		r2.setAngularVelocity(0);
		r1.setAngularVelocity(0);
		//r1.setAngularVelocity(0.001f);
		//listener=new CollisionListener(time);
		addRectangle(r1);
		addRectangle(r2);
		//addCircle(c1);
		//mover=new Moves(shapes,stb,str,stc,time);
	}
	
	public void addCircle(BodyCircle c){
		shapes.add(c.circle);
		stc.put(shapes.get(shapes.size()-1), c);
		stb.put(shapes.get(shapes.size()-1), c);
		stb.get(shapes.get(shapes.size()-1)).resetColXY();
		c.addColisionListener(listener);
	}
	
	public void addRectangle(BodyRectangle r){
		shapes.add(r.polygon);
		str.put(shapes.get(shapes.size()-1), r);
		stb.put(shapes.get(shapes.size()-1), r);
		stb.get(shapes.get(shapes.size()-1)).resetColXY();
		r.addColisionListener(listener);
	}
	
	
	
	


}